package com.usercar.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usercar.pojo.Festival;
import com.usercar.mapper.FestivalMapper;
import com.usercar.service.IFestivalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@Service
public class FestivalServiceImpl extends ServiceImpl<FestivalMapper, Festival> implements IFestivalService {

    @Autowired
    private FestivalMapper festivalMapper;

    @Override
    public Integer toInsert(Festival festival) {
        int i = festivalMapper.insert(festival);
        return i;
    }

    @Override
    public Festival selectById(Long festivalId) {
        Festival f = festivalMapper.selectById(festivalId);
        return f;
    }

    @Override
    public int updatefestivalId(Festival festival) {
        int i = festivalMapper.updateById(festival);
        return i;
    }

    @Override
    public Integer deleteById(Integer festivalId) {
        int i = festivalMapper.deleteById(festivalId);
        return i;
    }

    @Override
    public Map<String, Object> selectByPage(Integer pageNum, Integer pageSize) {
        /*QueryWrapper<Festival> q = new QueryWrapper<>();
        q.eq("年份属性",year);*/
        Page<Festival> page = new Page<>(pageNum,pageSize);
        Page<Festival> page1 = festivalMapper.selectPage(page,null);
        List<Festival> records = page1.getRecords();
        long total = page1.getTotal();
        Map<String,Object> map = new HashMap<>();
        map.put("list",records);
        map.put("total",total);
        return map;
    }

    @Override
    public List<Festival> selectByYear(String year) {
        Map<String,Object> map = new HashMap<>();
        map.put("year",year);
        List<Festival> festivals = festivalMapper.selectByMap(map);
        return festivals;
    }
}
